import java.util.*;

/*首先，要保证拿出至少一对匹配的手套
 *我们保证所有颜色都拿一只(在左右手套中选择数量相对较少的来拿所有颜色)
 *只需要用该边手套总数减去最少数量+1即可
 *然后另一边手套只需要拿1只就可以保证匹配
 *其次，考虑某个颜色一边数量为0的情况，要把另一边相应颜色的手套数加进去
 */
public class Gloves {
    public int findMinimum(int n, int[] left, int[] right) {
        // write code here
        int max1 = 0, max2 = 0;
        int min1 = 27, min2 = 27;
        for(int i = 0; i < n; i++){
            if(left[i] == 0){
                max1 = max1 + right[i];
            }else{
                max1 = max1 + left[i];
            }
            
            if(right[i] == 0){
                max2 = max2 + left[i];
            }else{
                max2 = max2 + right[i];
            }
            
            if(left[i] != 0 && right[i] != 0 && left[i] < min1){
                min1 = left[i];
            }
            
            if(right[i] != 0 && left[i] != 0 && right[i] < min2){
                min2 = right[i];
            }
        }
        max1 = max1 - (min1-1)+1;
        max2 = max2 - (min2-1)+1;
        return max1 < max2 ? max1 : max2;
    }
}